package com.zq.it.dao.impl.admin;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.zq.it.dao.admin.MajorDao;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.Major;

public class MajorDaoImpl extends BaseDao<Major> implements MajorDao {
  /*public static final Logger logger=t(MajorDaoImpl.class);*/
	@Override
	public void saveMajorEty(Major academty){
    	getHibernateTemplate().save(academty);
	}
	@Override
	public void deleteMajorEtyByID(Integer id){	
		deleteEntity("delete Major as m where m="+id);
	}

	@Override
	public List<Major> findMajorEtyList(){
		/*final List list=null;
		return getHibernateTemplate().executeFind(new HibernateCallback<List<Major>>(){
			@Override
			public List<Major>  doInHibernate(final Session arg0) throws HibernateException,
					SQLException {
				//org.hibernate.Transaction t=arg0.beginTransaction();
				// TODO Auto-generated method stub
		        return arg0.createCriteria(Major.class).setFetchMode("academy",org.hibernate.FetchMode.JOIN).list();
		    //   t.commit();
		         //return list;
			}
			
			});*/
		return getHibernateTemplate().find("from Major");
		// TODO Auto-generated method stub
	
	}

	@Override
	public List findMajorEtyByHql(String hql) {
		return getHibernateTemplate().find(hql);
		// TODO Auto-generated method stub
	
	}

	@Override
	public List findMajorEtyByName(String name) {
		return findEtyByHql("from Major as adm where adm.majorName like '%"+name+"%'");
		// TODO Auto-generated method stub
	
	}

//	@Override
//	public void updateMajorByID(Integer id) {
//		getHibernateTemplate().update(entity);
//		// TODO Auto-generated method stub
//		
//	}
	
	public List findMajorEtyByAcmyId(Integer id){
		//System.out.println(id);
		return getHibernateTemplate().find("from Major as m where m.academy.academyId=?",id);
	}
//public List findMajorEtyByHql(String hql){
//  ret getHibernateTemplate().find(hql);
//}
	@Override
	public void updateMajorEty(Major major) {
		getHibernateTemplate().saveOrUpdate(major);
		// TODO Auto-generated method stub		
	}
	@Override
	public List findMajorEtyByDate(Date date){
		return getHibernateTemplate().find("from Major as m where m.createDate=?",date);
	}
	@Override
	public List findMajorEtyByExmp(Major major) {
		// TODO Auto-generated method stub
		return getHibernateTemplate().findByExample(major);
	}
	@Override
	public void deleteAllEty(int[] ids){
		
		org.springframework.orm.hibernate3.HibernateTemplate ht=getHibernateTemplate();
				for(int i:ids)
				  ht.delete(ht.load(Major.class,i));
	}
	@Override
	public void deleteMajorEtyByObj(Major major){
		getHibernateTemplate().delete(major);
	}
	@Override
	public void saveMajorEtyList(Collection<Major> collection){
		getHibernateTemplate().saveOrUpdateAll(collection);
	}
	
	@Override
	public List findMajorEtyById(Integer id){
		// TODO Auto-generated method stub
		return findEtyByHql("from Major where majorId="+id);
	}
	public Major findMajorEty(Integer id){
		return getHibernateTemplate().get(Major.class, id);
	}
	@Override
	public List findMajorNameAndId() {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("select majorId,majorName from Major");
	}
}
